<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Batch and execute modifications on an LDAP entry</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.ldap-modify-batch" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ldap_modify_batch</h1>
  <p class="verinfo">(PHP 5.4 &gt;= 5.4.26, PHP 5.5 &gt;= 5.5.10, PHP 5.6 &gt;= 5.6.0, PHP 7)</p><p class="refpurpose"><span class="refname">ldap_modify_batch</span> &mdash; <span class="dc-title">Batch and execute modifications on an LDAP entry</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.ldap-modify-batch-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ldap_modify_batch</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$link_identifier</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$dn</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$entry</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$serverctrls</code><span class="initializer"> = array()</span></span>
  ] ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Modifies an existing entry in the LDAP directory. Allows detailed
   specification of the modifications to perform.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ldap-modify-batch-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">link_identifier</code></dt>

     <dd>

      <p class="para">
       An LDAP link identifier, returned by <span class="function"><a href="ldap_connect.html" class="function">ldap_connect()</a></span>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">dn</code></dt>

     <dd>

      <p class="para">
       The distinguished name of an LDAP entity.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">entry</code></dt>

     <dd>

      <p class="para">
       An array that specifies the modifications to make. Each entry in this
       array is an associative array with two or three keys:
       <em>attrib</em> maps to the name of the attribute to modify,
       <em>modtype</em> maps to the type of modification to perform,
       and (depending on the type of modification) <em>values</em>
       maps to an array of attribute values relevant to the modification.
      </p>
      <p class="para">
       Possible values for <em>modtype</em> include:
       <dl>

        
         <dt>
<strong><code>LDAP_MODIFY_BATCH_ADD</code></strong></dt>

         <dd>

          <p class="para">
           Each value specified through <em>values</em> is added (as
           an additional value) to the attribute named by
           <em>attrib</em>.
          </p>
         </dd>

        
        
         <dt>
<strong><code>LDAP_MODIFY_BATCH_REMOVE</code></strong></dt>

         <dd>

          <p class="para">
           Each value specified through <em>values</em> is removed
           from the attribute named by <em>attrib</em>. Any value of
           the attribute not contained in the <em>values</em> array
           will remain untouched.
          </p>
         </dd>

        
        
         <dt>
<strong><code>LDAP_MODIFY_BATCH_REMOVE_ALL</code></strong></dt>

         <dd>

          <p class="para">
           All values are removed from the attribute named by
           <em>attrib</em>. A <em>values</em> entry must
           not be provided.
          </p>
         </dd>

        
        
         <dt>
<strong><code>LDAP_MODIFY_BATCH_REPLACE</code></strong></dt>

         <dd>

          <p class="para">
           All current values of the attribute named by
           <em>attrib</em> are replaced with the values specified
           through <em>values</em>.
          </p>
         </dd>

        
       </dl>

      </p>
      <p class="para">
       Note that any value for <em>attrib</em> must be a string, any
       value for <em>values</em> must be an array of strings, and
       any value for <em>modtype</em> must be one of the
       LDAP_MODIFY_BATCH_* constants listed above.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">serverctrls</code></dt>

     <dd>

      <p class="para">
       Array of <a href="ldap.controls.html" class="link">LDAP Controls</a> to send with the request.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ldap-modify-batch-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.ldap-modify-batch-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.3</td>
       <td>
        Support for <code class="parameter">serverctrls</code> added
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ldap-modify-batch-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5403">
    <p><strong>Example #1 Add a telephone number to a contact</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$dn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"cn=John&nbsp;Smith,ou=Wizards,dc=example,dc=com"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$modifs&nbsp;</span><span style="color: #007700">=&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"attrib"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"telephoneNumber"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"modtype"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">LDAP_MODIFY_BATCH_ADD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"values"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;[</span><span style="color: #DD0000">"+1&nbsp;555&nbsp;555&nbsp;1717"</span><span style="color: #007700">],<br />&nbsp;&nbsp;&nbsp;&nbsp;],<br />];<br /></span><span style="color: #0000BB">ldap_modify_batch</span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$dn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$modifs</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
   <div class="example" id="example-5404">
    <p><strong>Example #2 Rename a user</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$dn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"cn=John&nbsp;Smith,ou=Wizards,dc=example,dc=com"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$modifs&nbsp;</span><span style="color: #007700">=&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"attrib"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"sn"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"modtype"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">LDAP_MODIFY_BATCH_REPLACE</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"values"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;[</span><span style="color: #DD0000">"Smith-Jones"</span><span style="color: #007700">],<br />&nbsp;&nbsp;&nbsp;&nbsp;],<br />&nbsp;&nbsp;&nbsp;&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"attrib"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"givenName"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"modtype"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">LDAP_MODIFY_BATCH_REPLACE</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"values"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;[</span><span style="color: #DD0000">"Jack"</span><span style="color: #007700">],<br />&nbsp;&nbsp;&nbsp;&nbsp;],<br />];<br /></span><span style="color: #0000BB">ldap_modify_batch</span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$dn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$modifs</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">ldap_rename</span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$dn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"cn=Jack&nbsp;Smith-Jones"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
   <div class="example" id="example-5405">
    <p><strong>Example #3 Add two e-mail addresses to a user</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$dn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"cn=Jack&nbsp;Smith-Jones,ou=Wizards,dc=example,dc=com"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$modifs&nbsp;</span><span style="color: #007700">=&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"attrib"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"mail"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"modtype"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">LDAP_MODIFY_BATCH_ADD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"values"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"jack.smith@example.com"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"jack.smith-jones@example.com"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;],<br />&nbsp;&nbsp;&nbsp;&nbsp;],<br />];<br /></span><span style="color: #0000BB">ldap_modify_batch</span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$dn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$modifs</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
   <div class="example" id="ldap-count-entries.example.basic">
    <p><strong>Example #4 Change a user&#039;s password</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$dn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"cn=Jack&nbsp;Smith-Jones,ou=Wizards,dc=example,dc=com"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$modifs&nbsp;</span><span style="color: #007700">=&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"attrib"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"userPassword"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"modtype"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">LDAP_MODIFY_BATCH_REMOVE</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"values"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;[</span><span style="color: #DD0000">"Tr0ub4dor&amp;3"</span><span style="color: #007700">],<br />&nbsp;&nbsp;&nbsp;&nbsp;],<br />&nbsp;&nbsp;&nbsp;&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"attrib"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"userPassword"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"modtype"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">LDAP_MODIFY_BATCH_ADD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"values"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;[</span><span style="color: #DD0000">"correct&nbsp;horse&nbsp;battery&nbsp;staple"</span><span style="color: #007700">],<br />&nbsp;&nbsp;&nbsp;&nbsp;],<br />];<br /></span><span style="color: #0000BB">ldap_modify_batch</span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$dn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$modifs</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
   <div class="example" id="example-5407">
    <p><strong>Example #5 Change a user&#039;s password (Active Directory)</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">adifyPw</span><span style="color: #007700">(</span><span style="color: #0000BB">$pw</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">iconv</span><span style="color: #007700">(</span><span style="color: #DD0000">"UTF-8"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"UTF-16LE"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'"'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$pw&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'"'</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$dn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"cn=Jack&nbsp;Smith-Jones,ou=Wizards,dc=ad,dc=example,dc=com"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$modifs&nbsp;</span><span style="color: #007700">=&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"attrib"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"unicodePwd"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"modtype"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">LDAP_MODIFY_BATCH_REMOVE</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"values"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;[</span><span style="color: #0000BB">adifyPw</span><span style="color: #007700">(</span><span style="color: #DD0000">"Tr0ub4dor&amp;3"</span><span style="color: #007700">)],<br />&nbsp;&nbsp;&nbsp;&nbsp;],<br />&nbsp;&nbsp;&nbsp;&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"attrib"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"unicodePwd"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"modtype"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">LDAP_MODIFY_BATCH_ADD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"values"&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;[</span><span style="color: #0000BB">adifyPw</span><span style="color: #007700">(</span><span style="color: #DD0000">"correct&nbsp;horse&nbsp;battery&nbsp;staple"</span><span style="color: #007700">)],<br />&nbsp;&nbsp;&nbsp;&nbsp;],<br />];<br /></span><span style="color: #0000BB">ldap_modify_batch</span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$dn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$modifs</span><span style="color: #007700">);</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>

</div></div></div></body></html>